package com.example.xbannertest;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;

import android.os.Bundle;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.blankj.utilcode.util.FragmentUtils;
import com.example.xbannertest.fragment.BannerFragment;

import java.util.ArrayList;
import java.util.List;

public class UserInFragmentActivity extends AppCompatActivity {

    private List<Fragment> mFragmentList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user_in_fragment);
        RadioGroup rbTab = findViewById(R.id.rg_tab);
        RadioButton radioButton = (RadioButton) rbTab.getChildAt(0);
        radioButton.setChecked(true);
        mFragmentList = new ArrayList<>();
        mFragmentList.add(BannerFragment.newInstance());
        mFragmentList.add(BannerFragment.newInstance());
        mFragmentList.add(BannerFragment.newInstance());
        mFragmentList.add(BannerFragment.newInstance());
        FragmentUtils.add(getSupportFragmentManager(), mFragmentList, R.id.fragment_content, 0);

        rbTab.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId) {
                    case R.id.tab_1:
                        FragmentUtils.showHide(0, mFragmentList);
                        break;
                    case R.id.tab_2:
                        FragmentUtils.showHide(1, mFragmentList);
                        break;
                    case R.id.tab_3:
                        FragmentUtils.showHide(2, mFragmentList);
                        break;
                    case R.id.tab_4:
                        FragmentUtils.showHide(3, mFragmentList);
                        break;
                    default:
                        break;
                }
            }
        });
    }
}